package com.bbm.communitysystem.core.filter;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class Verify {

    private final String ERROR_KEY = "ERROR_IS_ME:";

    public boolean verifyAdmin(HttpServletRequest request) {
        String s = request.getAttribute("filter") + "";
        return s.equals("admin");
    }

    public boolean verifyError(HttpServletRequest request) {
        String s = request.getAttribute(ERROR_KEY) + "";
        if (s.equals("null")) {
            return false;
        }
        return !s.isEmpty();
    }

    public String getError(HttpServletRequest request) {
        return request.getAttribute(ERROR_KEY) + "";
    }

    public void addError(HttpServletRequest request, String error) {
        request.setAttribute(ERROR_KEY, error);
    }

}
